/*
 * @Autor: Haiting Zhao
 * @Date: 2022-02-26 14:42:26
 * @LastEditors: Haiting Zhao
 * @LastEditTime: 2022-04-05 20:13:26
 * @Description: file content
 * @FilePath: \league_and_student_organization_management_system_font\src\main.js
 */
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import axios from 'axios'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// import ViewUI from 'view-design'
// import 'view-design/dist/styles/iview.css'
Vue.config.productionTip = false
Vue.prototype.$http = axios
Vue.prototype.axios = axios
axios.defaults.baseURL = '/api'
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
axios.defaults.headers.post['Content-Type'] = 'application/json'

axios.interceptors.request.use(config => {
  NProgress.start()
  return config
}, error => {
  return Promise.reject(error)
})

axios.interceptors.response.use(response => {
  NProgress.done()
  return response
}, error => {
  if (error.response.data.code === 403) {
    this.$router.push('/' + crypto.set(43))
  } else if (error.response.data.code === 404) {
    this.$router.push('/' + crypto.set(44))
  } else if (error.response.data.code === 500) {
    this.$router.push('/' + crypto.set(45))
  } else if (error.response.data.code === 401) {
    window.sessionStorage.clear()
    this.$router.push('/')
    window.location.reload()
  }
  return Promise.reject(error)
})
Vue.use(ElementUI)
// Vue.use(ViewUI)
new Vue({
  components: {
    App
  },
  router,
  store,
  render: h => h(App)
}).$mount('#app')
